using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FiltronASP.Modules.Abstracts;
using FiltronASP.Models.DAO.Interfaces;
using FiltronASP.Models;
using FiltronASP.Models.DAO;
using FiltronASP.Helpers.Constants;
using FiltronASP.Helpers.Translations;

namespace FiltronASP.Modules
{
    public class implementationsAllMonth : AbstractModule
    {

        /// <summary>
        /// Klasa odpowiedzialna za generowanie contentu przez modul.
        /// </summary>
        /// <param name="page">biezaca strona</param>
        /// <returns>content</returns>
        public override string GenerateContent(FiltronASP.Models.Page page)
        {
            int languageId = Convert.ToInt32(page.language_id);
            IPageDAO PageDAO = new PageDAO();
            IQueryable<Page> MonthsCollection = PageDAO.FindByLanguageAndTemplateNameAndPublished(7, "NewsSingleMonth", true);
            List<String> MonthsList = new List<String>();
            if (MonthsCollection != null)
            {
                MonthsCollection = MonthsCollection.OrderBy(p => p.page_ordering);
                foreach (Page singleMonth in MonthsCollection)
                {
                    MonthsList.Add(singleMonth.page_name);
                }
            }

            String implementationsHtml = String.Empty;
            String currentYear = "";
            int MonthCounter = 0;
            if (MonthsList != null)
            {

                implementationsHtml += "<div class=\"col-xs-12 no-padding\" style=\"margin-bottom: 40px;\">";
                implementationsHtml += "  <!--     selekty start-->";
                implementationsHtml += "   <div class=\"col-md-4 col-sm-6  col-xs-12 kat-sub-select mar-top-20\">";
                implementationsHtml += " <div class=\"col-xs-12 ajax-loader-select-only\" >";
                implementationsHtml += " <img class=\"img-responsive\" id='yearsLoader' src=\"" + VirtualPathUtility.ToAbsolute("~/Content/img/ajax-loader.gif") + "\" alt=\"loading\" style=\"  margin: 0 auto; margin-top: 12px; display: none;\">";
                implementationsHtml += " </div>";
                implementationsHtml += "<div class=\"col-sm-4  col-xs-12 padd-l-0\">";
                implementationsHtml += String.Format(" <p>{0}:</p>", translationHelper.getTranslation("_year", languageId).ToUpper());
                implementationsHtml += " </div>";
                implementationsHtml += "<div class=\"col-sm-8  col-xs-12 padding-0\">";
                implementationsHtml += "<select id='yearsId'>";
                implementationsHtml += String.Format("<option value='-1'>{0}</option>", translationHelper.getTranslation("_chooseYear", languageId));
                List<String> YearList = new List<String>();
                foreach (String currentMonth in MonthsList)
                {
                    String splittedMonth = currentMonth.Split(' ')[0];
                    String splittedYear = currentMonth.Split(' ')[1];
                    if (!YearList.Contains(splittedYear))
                    {
                        YearList.Add(splittedYear);
                    }
                }
                foreach (String disYear in YearList)
                {
                    implementationsHtml += "<option value="+disYear + ">" + disYear + "</option>";
                }
                implementationsHtml += " </select>";
                implementationsHtml += " </div>";
                implementationsHtml += " </div>";
                implementationsHtml += " <div class=\"col-md-4 col-sm-6    col-xs-12 kat-sub-select mar-top-20\">";
                implementationsHtml += " <div class=\"col-xs-12 ajax-loader-select-only\" >";
                implementationsHtml += " <img class=\"img-responsive\" id='monthsLoader' src=\""+VirtualPathUtility.ToAbsolute("~/Content/img/ajax-loader.gif") + "\" alt=\"loading\" style=\"  margin: 0 auto; margin-top: 12px; display: none;\">";
                implementationsHtml += " </div>";
                implementationsHtml += "  <div class=\"col-sm-4  col-xs-12 padd-l-0\">";
                implementationsHtml += String.Format("<p>{0}:</p>", translationHelper.getTranslation("_month", languageId).ToUpper());
                implementationsHtml += "  </div>";
                implementationsHtml += "   <div class=\"col-sm-8  col-xs-12 padding-0\">";
                implementationsHtml += "      <select id='monthSelectId'>";
                implementationsHtml += String.Format("<option value='-1'>{0}</option>", translationHelper.getTranslation("_chooseMonth", languageId));
                implementationsHtml += "   </select>";
                implementationsHtml += " </div>";
                implementationsHtml += "  </div>";
                implementationsHtml += "      <!--    selekty end-->";
                implementationsHtml += "  </div>";
            }
                
            return implementationsHtml;
        }

    }
}
